<?php

namespace App\Models;

use App\Engine\BaseModel;
use Illuminate\Database\Eloquent\Model;

class Image extends BaseModel
{
    protected $fillable=['url','category'];
    /**添加图片到数据库
     * @param $url
     * @param $cid
     * @return mixed
     */
    public static function add($url,$cid)
    {
        $data=[
            'url'=>$url,
            'category'=>$cid
        ];
        $res=self::create($data);
        return $res;
    }

    /**获取图片
     * @param string $category
     * @return mixed
     */
    public static function get_image($category="")
    {
        if($category=="")
            return self::orderBy('id','desc')->get();
        else
            return self::where('category',$category)->get();
    }
}
